package com.css.fxfzaqbz.modules.assess.repository.impl;

import com.css.fxfzaqbz.constants.YNEnum;
import com.css.fxfzaqbz.modules.assess.entity.DisasterAssEntity;
import com.css.fxfzaqbz.modules.assess.repository.ResultAnalysisRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class ResultAnalysisRepositoryImpl implements ResultAnalysisRepository {
    @Resource
    JdbcTemplate jdbcTemplate;
    @Override
    public Map<String, Object> getResult(int curPage, int pageSize, String id) {
        String sql="select * from sys_disaster_assessment  where del_flag = '"+ YNEnum.N.toString() +"' and sda_relation='"+id+"' and sda_ass_sei_intensity = '房屋破坏评估' and data_message ='计算评估' order by create_time desc";//
        Integer total = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DisasterAssEntity.class)).size();
        int firstIndex=(curPage-1) * pageSize;
        int lastIndex=pageSize;
        StringBuilder limitSql = new StringBuilder(" limit "+lastIndex+" offset "+ firstIndex);
        List<DisasterAssEntity> list = jdbcTemplate.query(sql+limitSql, new BeanPropertyRowMapper<>(DisasterAssEntity.class));
        Map<String,Object> map=new HashMap();
        map.put("total",total);
        map.put("rows",list);
        return map;
    }
}
